package ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wb.swt.SWTResourceManager;

import each_class.SongClass;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackListener;

//显示歌民和歌手
//2021年6月20日修改：增加了initial方法
public class MusicInfo extends Composite implements MouseTrackListener, MouseListener {

	protected Label name;
	protected Label separator;
	protected Label singer;

	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public MusicInfo(Composite parent, int style) {
		super(parent, style);
		setVisible(true);
		setSize(new Point(384, 20));
		RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL);
		rl_composite.wrap = false;
		rl_composite.marginTop = 0;
		rl_composite.marginRight = 0;
		rl_composite.marginLeft = 0;
		rl_composite.marginBottom = 0;
		setLayout(rl_composite);
		name = new Label(this, SWT.HORIZONTAL);
		name.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				ui.global.Operation.search(name.getText());
			}
		});
		name.setAlignment(SWT.RIGHT);
		name.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		name.setText("\u6682\u65E0\u6B4C\u66F2");

		separator = new Label(this, SWT.NONE);
		separator.setAlignment(SWT.CENTER);
		separator.setText("-");

		singer = new Label(this, SWT.NONE);
		singer.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				ui.global.Operation.search(singer.getText());
			}
		});
		singer.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		singer.setText("\u4F5A\u540D");
		addMouseTrackListener(this);
		addMouseListener(this);
		singer.addMouseTrackListener(this);
		name.addMouseTrackListener(this);
		layout();

	}

	public void clear() {
		name.setText("\u6682\u65E0\u6B4C\u66F2");
		singer.setText("\u4F5A\u540D");
	}

	@Override
	protected void checkSubclass() {
	}

	@Override
	public void setFont(Font font) {
		name.setFont(font);
		separator.setFont(font);
		singer.setFont(font);
	}

	@Override
	public void setBackground(Color color) {
		super.setBackground(color);
		name.setBackground(color);
		separator.setBackground(color);
		singer.setBackground(color);
	}

	// 切换歌曲时调用
	public void initail(SongClass music) {
		if (music.getSong_name() != null) {
			name.setText(music.getSong_name());
			singer.setText(music.getSingerString());
		}

	}

	@Override
	public void mouseEnter(MouseEvent e) {
	}

	@Override
	public void mouseExit(MouseEvent e) {
	}

	@Override
	public void mouseHover(MouseEvent e) {
	}

	@Override
	public void mouseDoubleClick(MouseEvent e) {
	}

	@Override
	public void mouseDown(MouseEvent e) {

	}

	@Override
	public void mouseUp(MouseEvent e) {
	}
}
